﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AddExpertGain : PX.MyPage
{
	private PX.Expert.ExpertComponent clsExpertComp = new PX.Expert.ExpertComponent();
	private PX.ExpertGain.Component clsExpertGainComp = new PX.ExpertGain.Component();

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			TBDate.Text = System.DateTime.Now.ToShortDateString();

			BindExpertDropDownList();
		}
	}

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);

		clsExpertComp.page = Page;
		clsExpertGainComp.page = Page;

		TBDate.Attributes.Add("onClick", "popUpCalendar(this, this, 'yyyy-mm-dd')");

		LBtnAdd.Click += new EventHandler(LBtnAdd_Click);
	}

	void LBtnAdd_Click(object sender, EventArgs e)
	{
		if (AddExpertGain())
		{
			Common.ShowMessageAlert.ShowMessage(Page, "添加成功！");
		}
	}

	/// <summary>
	/// 绑定大师下拉列表
	/// </summary>
	private void BindExpertDropDownList()
	{
		int nDepartmentID;

		nDepartmentID = Convert.ToInt32(Session["LoginUserDepartmentID"]);

		clsCommonControl.ExpertByDepartment(DdlExpert, nDepartmentID);
	}

	/// <summary>
	/// 添加大师成果
	/// </summary>
	/// <returns></returns>
	private bool AddExpertGain()
	{
		PX.ExpertGain.Entity clsGain = new PX.ExpertGain.Entity();
		PX.UploadFile.UploadFileComponent clsFileContentComp = new PX.UploadFile.UploadFileComponent();
		PX.UploadFile.UploadFile clsFileContent = new PX.UploadFile.UploadFile();
		PX.UploadFile.UploadFile clsGainConent = new PX.UploadFile.UploadFile();

		clsFileContentComp.page = Page;

		if (clsFileContentComp.Add(FUploadImage, clsFileContent))
		{
			if (clsFileContentComp.Add(FUpload, clsGainConent))
			{
				clsGain.ExpertUserID = Convert.ToInt32(DdlExpert.Text);
				clsGain.Name = TBName.Text;
				clsGain.ImageID = clsFileContent.ID;
				clsGain.Content = TBContent.Text;
				clsGain.ObtainDate = TBDate.Text;
				clsGain.DateTime = System.DateTime.Now.ToString();
				clsGain.ExpertDepartmentID = Convert.ToInt32(Session["LoginUserDepartmentID"]);
				clsGain.UserID = Convert.ToInt32(Session["LoginUserID"]);
				clsGain.FileContentID = clsGainConent.ID;

				if (clsExpertGainComp.Add(clsGain))
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
}